package com.cl.short_video_java.web.sys_setting;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.annotation.Log;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.annotation.NoRepeatSubmit;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.menum.BusinessType;
import com.cl.short_video_java.pojo.AlipayConfig;
import com.cl.short_video_java.pojo.SysSetting;
import com.cl.short_video_java.service.SysSettingService;
import com.cl.short_video_java.vo.setting.Alipay;
import com.cl.short_video_java.vo.sys.Setting;
import com.cl.short_video_java.vo.sys.SettingSearch;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author 付
 * @Date 2024-11-03 14:32
 * @Version 1.0
 * @description
 * @since 1.0
 */
@RestController
@RequestMapping("/setting")
public class SysSettingController {

	private SysSettingService sysSettingService;

	public SysSettingController(SysSettingService sysSettingService) {
		this.sysSettingService = sysSettingService;
	}

	/**
	 * 获取设置列表
	 *
	 * @return
	 */
	@PostMapping("/list")
	@Login(issuer = Const.GRADE_ADMIN)
	public Result getSysSetting(@RequestBody SettingSearch settingSearch) {
		return Result.success(sysSettingService.search(settingSearch));
	}

	/**
	 * 数据操作
	 *
	 * @param key  数据key
	 * @param type 操作字符，2-删除，3-是否禁用
	 * @return
	 */
	@GetMapping("/oper")
	public Result oper(@RequestParam("key") String key, @RequestParam("type") Integer type) {
		sysSettingService.oper(key, type);
		return Result.success();
	}

	/**
	 * 字典：修改-新增
	 *
	 * @param setting 提交参数
	 * @return 操作结果
	 */
	@PostMapping("/add")
	public Result add(@Validated @RequestBody Setting setting) {
		Result result = sysSettingService.insertOrUpdate(setting);
		return result;
	}

	@PostMapping("/batch-del")
	public Result batchDel(@RequestBody List<String> list) {
		System.out.println(list);
		sysSettingService.batchDelete(list);
		return Result.success();
	}

	/**
	 * 获取支付宝的支付配置信息
	 *
	 * @return
	 */
	@GetMapping("/alipay")
	public Result getAlipay() {
		Map<String, AlipayConfig> list = sysSettingService.alipay();
		return Result.success(list);
	}

	@Log(title = "支付宝支付配置", businessType = BusinessType.UPDATE)
	@PostMapping("/alipay")
	public Result alipay(@Validated @RequestBody Alipay alipay) {
		sysSettingService.save(alipay);
		return Result.success();
	}

}
